package project01;

//家庭收支记账
public class FamilyAccount {
    public static void main(String[] args) {
        boolean isFlag = true;
        //初始金额
        int balance = 10000;
        //用于记录用户的收入和支出详情
        String details = "收支\t\t账户金额\t\t收支金额\t\t说  明\n";
        do {
            System.out.println("***********家庭收支记账软件***********\n");
            System.out.println("\t\t\t1 收支明细");
            System.out.println("\t\t\t2 登记收入");
            System.out.println("\t\t\t3 登记支出");
            System.out.println("\t\t\t4 退   出\n");
            System.out.print("\t\t\t请选择(1-4):");

            char selection = Utility.readMenuSelection();
            switch (selection) {
                case '1':
                    System.out.println("-----------当前收支明细记录-----------");
                    System.out.println(details);
                    System.out.println("-----------------------------------");
                    break;
                case '2':
                    System.out.print("本次收入金额:");
                    int addMoney = Utility.readNumber();
                    System.out.print("本次收入说明:");
                    String addInfo = Utility.readString();
                    //处理账户金额
                    balance += addMoney;
                    //处理details
                    details += ("收入\t\t" + balance + "\t\t" + addMoney + "\t\t\t" + addInfo + "\n");
                    System.out.println("--------------登记完成--------------\n");
                    break;
                case '3':
                    System.out.print("本次支出金额:");
                    int minusMoney = Utility.readNumber();
                    System.out.print("本次支出说明:");
                    String minusInfo = Utility.readString();

                    if (balance>=minusMoney){
                        //处理账户金额
                        balance-=minusMoney;
                        //处理details
                        details += ("收入\t\t" + balance + "\t\t" + minusMoney + "\t\t\t" + minusInfo + "\n");
                    }else {
                        System.out.println("支出超出账户额度,支付失败");
                    }
                    break;
                case '4':
                    System.out.print("确认是否退出(Y/N):");
                    char isExit = Utility.readConfirmSelecton();
                    if (isExit == 'Y') {
                        isFlag = false;
                    }
                    break;
            }

        } while (isFlag);
    }
}
